package com.ofsoft.weixin.mp.api;

/**
 * 菜单接口
 * 
 * @author OF
 * @date 2017年10月17日
 */
public class MenuApi extends ApiBase {
	private static String menuCreateUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=";

	/**
	 * 创建菜单
	 * 
	 * @param jsonMenu
	 *            菜单json
	 * @return ApiResponse
	 */
	public static ApiResponse cretaMenu(String jsonMenu) {
		String url = menuCreateUrl + AccessTokenConfig.getAccessToken();
		return sendPost(url, jsonMenu);
	}

	private static String queryCreateUrl = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=";

	/**
	 * 查询菜单
	 * 
	 * @param accessToken
	 *            自定义token
	 * @return ApiResponse
	 */
	public static ApiResponse getMenu(String accessToken) {
		String url = queryCreateUrl + accessToken;
		return sendGet(url);
	}

	/**
	 * 查询菜单
	 * 
	 * @return ApiResponse
	 */
	public static ApiResponse getMenu() {
		String url = queryCreateUrl + AccessTokenConfig.getAccessToken();
		return sendGet(url);
	}

	private static String deleteUrl = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=";

	/**
	 * 删除菜单
	 * 
	 * @return ApiResponse
	 */
	public static ApiResponse deleteMenu() {
		String url = deleteUrl + AccessTokenConfig.getAccessToken();
		return sendGet(url);
	}

	private static String addConditional = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=";

	/**
	 * 创建个性化菜单
	 * 
	 * @param jsonMenu
	 *            菜单json
	 * @return ApiResponse
	 */
	public static ApiResponse addConditional(String jsonMenu) {
		String url = addConditional + AccessTokenConfig.getAccessToken();
		return sendPost(url, jsonMenu);
	}

	private static String delConditional = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=";

	/**
	 * 删除个性化菜单
	 * 
	 * @param menuId
	 *            菜单编号
	 * @return ApiResponse
	 */
	public static ApiResponse delConditional(String menuId) {
		String url = delConditional + AccessTokenConfig.getAccessToken();
		return sendPost(url, new ApiRequest().set("menuid", menuId));
	}

	private static String trymatch = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=";

	/**
	 * 测试个性化菜单
	 * 
	 * @param userId
	 *            user_id可以是粉丝的OpenID，也可以是粉丝的微信号。
	 * @return ApiResponse
	 */
	public static ApiResponse trymatch(String userId) {
		String url = trymatch + AccessTokenConfig.getAccessToken();
		return sendPost(url, new ApiRequest().set("user_id", userId));
	}
}
